package com.wn.consumer;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author yellow Docter
 * @date 2023 -07-26
 * @desc
 *  测试 topic 交换机
 *  topic 类型的交换机:
 *   发送到类型是 topic 交换机的消息的 routing_key 不能随意写，
 *   必须满足一定的要求，它**必须是一个单词列表，以点号分隔开
 *
 *   * 可以替换一个单词
 *            hello.*
 *            hello.abc
 *   # 可以替代零个或多个单词
 *            hello.#
 *            hello.ab
 *            hello.abc.abc
 *
 */
@Component
public class C2 {

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "Q2"),
                    exchange = @Exchange(
                       name = "exchange-topic",
                       type = ExchangeTypes.TOPIC
                    ),
                    key = {
//                            "*.orange.*",   //三个单词   包含 orange  就能匹配
                            "*.*.rabbit",   //三个单词   以rabbit 结尾
                            "lazy.#",       //多个单词   以 lazy 开头
                    }
            )
    )
    public void handlerMsg(String msg){
        System.out.println("C2 消费者:消费的消息=====>" + msg);
    }

}
